/**
 * Copyright 2014 lerry
 * 
 * All right reserved.
 * 
 * Dec 22, 2014
 */
package com.bac.bacplatform;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bac.utils.Config;
import com.bac.utils.LockPatternUtils;

/**
 * @author lerry
 *
 */
public class PersonalPwdManagerActivity extends BaseActivity implements OnClickListener{
	RelativeLayout rl_modify_gesture = null;
	RelativeLayout rl_back_paypwd = null;
	RelativeLayout rl_edit_loginpwd = null;
	RelativeLayout rl_edit_paypwd = null;
	
	private ImageView mIsGestureView;
	private LockPatternUtils lockPatternUtils;
	private boolean gestureIsSet = false;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.my_password);
		findViewById(R.id.title_left).setOnClickListener(this);
		
		
		rl_modify_gesture = (RelativeLayout)findViewById(R.id.modify_guesture);
		mIsGestureView = (ImageView)findViewById(R.id.go_edit);
	}

	@Override
	public void init() {
		lockPatternUtils = new LockPatternUtils(this);
		
		if(lockPatternUtils.getLockPaternString()!=""&&lockPatternUtils.getLockPaternString()!=null){
			gestureIsSet = true;
			mIsGestureView.setImageResource(R.drawable.recharge_switch_on);
			rl_modify_gesture.setVisibility(View.VISIBLE);
		}else{
			gestureIsSet = false;
			rl_modify_gesture.setVisibility(View.GONE);
			mIsGestureView.setImageResource(R.drawable.recharge_switch_off);
		}

		rl_edit_loginpwd = (RelativeLayout) findViewById(R.id.edit_loginpwd);
		rl_edit_loginpwd.setOnClickListener(this);
//		rl_find_back_pwd = (RelativeLayout) findViewById(R.id.find_back_pwd);
//		rl_find_back_pwd.setOnClickListener(this);
		rl_back_paypwd = (RelativeLayout) findViewById(R.id.back_paypwd);
		rl_back_paypwd.setOnClickListener(this);
		rl_edit_paypwd = (RelativeLayout) findViewById(R.id.edit_paypwd);
		rl_edit_paypwd.setOnClickListener(this);
		
//		findViewById(R.id.loginpwd).setOnClickListener(this);
		findViewById(R.id.modify_guesture).setOnClickListener(this);
		findViewById(R.id.edit_handpwd).setOnClickListener(this);
		
		if (Config.UserGeneralInfo.wealthAccountBanding) {
			rl_back_paypwd.setEnabled(true);
			rl_back_paypwd.setBackgroundColor(Color.TRANSPARENT);
			rl_edit_paypwd.setEnabled(true);
			rl_edit_paypwd.setBackgroundColor(Color.TRANSPARENT);
		}else{
			rl_back_paypwd.setEnabled(false);
			rl_back_paypwd.setBackgroundColor(0xFFD3D3D3);
			rl_edit_paypwd.setEnabled(false);
			rl_edit_paypwd.setBackgroundColor(0xFFD3D3D3);
		}
		
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.title_left:
			finishActivityOut();
			break;
		case R.id.modify_guesture:
			Intent intentModify = new Intent(PersonalPwdManagerActivity.this, LockActivity.class);
			if (gestureIsSet) {
				intentModify.putExtra("action", "modify_gesture");
			}
			startActivityIn(intentModify);
			break;
		case R.id.edit_loginpwd:
			Intent intentToEditLoginPwd = new Intent(PersonalPwdManagerActivity.this,EditLoginPwdActivity.class);
			startActivity(intentToEditLoginPwd);
			break;
//		case R.id.find_back_pwd:
//			Intent intentToLoginPwd = new Intent(PersonalPwdManagerActivity.this,LoginPwdActivity.class);
//			startActivity(intentToLoginPwd);
//			break;
		case R.id.edit_paypwd:
			Intent intentToEditPayPwd = new Intent(PersonalPwdManagerActivity.this,EditPayPwdActivity.class);
			startActivity(intentToEditPayPwd);
			break;
		case R.id.back_paypwd:
			Intent intentToPayPwd = new Intent(PersonalPwdManagerActivity.this,PayPwdActivity.class);
			startActivity(intentToPayPwd);
			break;
		case R.id.edit_handpwd:
			Intent intentReset1 = new Intent(PersonalPwdManagerActivity.this, LockActivity.class);
			if (gestureIsSet) {
				intentReset1.putExtra("action", "close_gesture");
			}else{
				intentReset1.putExtra("action", "set_gesture");
			}
			
			startActivityIn(intentReset1);
//			this.showToast("设置手势密码");
			break;
		default:
			break;
		}
		
	}
	
//	private void visible(int i) {
//		findViewById(R.id.cb_cmd).setVisibility(View.INVISIBLE);
//		findViewById(R.id.cb_gesture).setVisibility(View.INVISIBLE);
//		if(i==1){
//			findViewById(R.id.cb_cmd).setVisibility(View.VISIBLE);
//		} else if(i==2){
//			findViewById(R.id.cb_gesture).setVisibility(View.VISIBLE);
//		}
//	}

}
